//
//  RoomMateListViewController.m
//  Fangmm
//
//  Created by ChaoZhou on 16/3/21.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "RoomMateListViewController.h"
#import "HttpServer.h"
#import "RoomMateListTableViewCell.h"
#import <UIButton+WebCache.h>
#import "Seat.h"
#import "UserHomepageViewController.h"
@interface RoomMateListViewController ()<UITableViewDataSource,UITableViewDelegate,RoomMateListTableViewCellDelegate>
{
    NSMutableArray *menberArray;
}

@end

@implementation RoomMateListViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"室友列表";
    UIBarButtonItem *leftBar = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"back-18-36"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(goToBack)];
    self.navigationItem.leftBarButtonItem = leftBar;
    menberArray = [NSMutableArray array];
    [_mainTableView registerNib:[UINib nibWithNibName:@"RoomMateListTableViewCell" bundle:nil] forCellReuseIdentifier:@"RoomMateListTableViewCell"];
    _mainTableView.tableFooterView = [UIView new];
    [self parserTeamToMenber];
}
-(void)goToBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)parserTeamToMenber
{
    for (Seat *seatMember in self.team.seatArray)
    {
        if (seatMember.userId)
        {
            [menberArray addObject:seatMember];
        }
    }
    NSLog(@"***%lu",(unsigned long)menberArray.count);
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return menberArray.count ;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Seat *memberSeat = ((Seat*)(menberArray[indexPath.row]));
    RoomMateListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomMateListTableViewCell"];
    [cell.headerImage sd_setBackgroundImageWithURL:[NSURL URLWithString:memberSeat.userAvatar] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"houseown"]];
    cell.nameLabel.text = memberSeat.userName;
    cell.roomSeat.text = memberSeat.roomName;
    cell.userId = memberSeat.userId;
    cell.userName = memberSeat.userName;
    cell.delegate = self;
    if ([memberSeat.userGender isEqualToString:@"f"])
    {
        [cell.sexImage setImage:[UIImage imageNamed:@"girl_22-22"]];
    }
    if ([memberSeat.userGender isEqualToString:@"m"])
    {
        [cell.sexImage setImage:[UIImage imageNamed:@"boy_22-22"]];
    }
    return cell;
}
-(void)clickHeaderImageWithUserId:(NSString *)userId withUserName:(NSString *)userName
{
    UserHomepageViewController *userHomepageVC = [[UserHomepageViewController alloc]init];
    userHomepageVC.userId = userId;
    userHomepageVC.userName = userName;
    [self.navigationController pushViewController:userHomepageVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
